<%@page import="java.net.URLDecoder"%>
<%@page import="com.google.appengine.api.datastore.Entity"%>
<%@page import="java.util.List"%>
<%@page import="com.google.appengine.api.datastore.FetchOptions"%>
<%@page import="com.google.appengine.api.datastore.PreparedQuery"%>
<%@page import="com.google.appengine.api.datastore.Query.SortDirection"%>
<%@page import="com.google.appengine.api.datastore.Query"%>
<%@page
	import="com.google.appengine.api.datastore.DatastoreServiceFactory"%>
<%@page import="com.google.appengine.api.datastore.DatastoreService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cba Page Rank Top 10</title>
<%
	DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
	Query query = new Query("CbaPage");
	query.addSort("cbaCount", SortDirection.DESCENDING);
	PreparedQuery pq = ds.prepare(query);
	FetchOptions f = FetchOptions.Builder.withLimit(10);
	List<Entity> list = pq.asList(f);
%>
<style type="text/css">
.cba-count {
	width: 80px;
	text-align: right;
	display: inline-block;
	border-radius: 5px;
	padding: 5px;
	background-color: #eee;
	color: #f63;
	border: solid 1px silver;
	font-size: 0.7em;
}

.cba-link {
	display: inline-block;
}

li {
	margin: 10px 0px;
}

body {
	background-image: url("images/icon128.png");
	background-position: top left;
	background-repeat: no-repeat;
	padding-left: 150px;
}
</style>

</head>
<body>
	<h1>CBA TOP 10</h1>
	<ol>
		<%
			for (Entity each : list) {
		%>
		<%
			String url = URLDecoder
						.decode(each.getKey().getName(), "UTF-8");
		%>
		<li><div class="cba-count"><%=each.getProperty("cbaCount")%>
				cbas
			</div>
			<div class="cba-link">
				<a href="<%=url%>"><%=url%></a>
			</div></li>
		<%
			}
		%>
	</ol>
</body>
</html>